package com.sheledon.demo.demo1.controller;

import com.sheledon.demo.pojo.User;
import com.sheledon.demo.demo1.service.UserService;
import com.sheledon.flyCat.annotation.ioc.Autowired;
import com.sheledon.flyCat.annotation.ioc.Qualifier;
import com.sheledon.flyCat.annotation.springmvc.*;

/**
 * @author sheledon
 */
@RestController("/user")
public class UserController {
    @Autowired
    @Qualifier(name = "us")
    private UserService userService;

    @GetMapping("/{id}")
    public User getUserById(@PathVariable("id") int id){
        System.out.println(userService);
        return userService.getUserById(id);
    }
    @GetMapping("/")
    public User getUserById2(@RequestParam(name = "id") int id){
        return userService.getUserById(id);
    }

    @GetMapping("/{name}/join/{id}")
    public User getUserById3(@PathVariable("id") int id,@PathVariable("name") String name){
        return userService.getUserById(id,name);
    }
    @PostMapping("/")
    public User saveUser(@RequestBody User user){
        userService.saveUser(user);
        return user;
    }
}
